<template>
  <div>
    <!-- 商品分类导航 -->
    <div class="type-nav">
      <div class="container">
        <h2 class="all">全部商品分类</h2>
        <nav
          class="nav"
          v-for="(type, index) in typeList"
          :key="type.tid"
          v-if="index < 10"
        >
          <a href="###">{{ type.tname }}</a>
        </nav>
        <div class="sort">
          <div class="all-sort-list2">
            <div
              class="item"
              v-for="(brand, index) in brandsList"
              :key="brand.bid"
            >
              <h3>
                <a href="#" @click="goSearch(brand)">{{ brand.bname }}</a>
              </h3>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
// 映射仓库数据
import { mapState } from "vuex";
export default {
  name: "TypeNav",
  data() {
    return {};
  },
  computed: {
    // 计算仓库属性
    ...mapState({
      brandsList: (state) => state.home.brandsList,
      typeList: (state) => state.home.typeList,
    }),
  },
  mounted() {
    this.$store.dispatch("getAllBrands");
    this.$store.dispatch("getAllTypes");
  },

  methods: {
    goSearch(brand) {
      let bid = brand.bid;
      let location = {
        name: "search",
        query: { bid: bid },
      };
      // location.query = query;
      this.$router.push(location);
    },
  },
};
</script>

<style lang="less" scoped>
.type-nav {
  border-bottom: 2px solidr gb(3, 138, 143);
  .container {
    width: 1200px;
    // height: 800px;
    margin: 0 auto;
    display: flex;
    position: relative;
    .all {
      width: 210px;
      height: 45px;
      background-color: rgb(3, 138, 143);
      line-height: 45px;
      text-align: center;
      color: #fff;
      font-size: 14px;
      font-weight: bold;
    }

    .nav {
      a {
        height: 45px;
        margin: 0 22px;
        line-height: 45px;
        font-size: 16px;
        color: rgb(0, 61, 63);
      }
    }

    .sort {
      position: absolute;
      left: 0;
      top: 45px;
      width: 210px;
      height: 550px;
      position: absolute;
      background: #f0efef;
      z-index: 999;

      .all-sort-list2 {
        .item {
          h3 {
            line-height: 30px;
            font-size: 14px;
            font-weight: 400;
            overflow: hidden;
            padding: 0 20px;
            margin: 0;

            a {
              color: #333;
            }
          }

          &:hover {
            color: white;
            background-color: rgb(174, 206, 206);
            .item-list {
              display: block;
            }
          }
        }
      }
    }
  }
}
</style>